package com.wyzz.hr.action;

import com.wyzz.hr.base.BaseAction;
import com.wyzz.hr.bo.ICompaplanBo;
import com.wyzz.hr.bo.IEmpBenefitPlanBo;
import com.wyzz.hr.bo.IEmpSalaryAcctversionBo;
import com.wyzz.hr.bo.ISalaryPaidBo;
import com.wyzz.hr.bo.ISalaryconfBo;
import com.wyzz.hr.pojo.Empsalaryacctversion;

public class DelEmpsalaryacct extends BaseAction {

	public DelEmpsalaryacct() {
		msgNoData = "\u85AA\u8D44\u5E10\u5957\u7248\u672C\u4E0D\u5B58\u5728\uFF0C\u8BF7\u5237\u65B0\u540E\u91CD\u8BD5\uFF01";
		msgHistVer = "{0}\u4E3A\u5386\u53F2\u7248\u672C\uFF0C\u4E0D\u5141\u8BB8\u5220\u9664\uFF01";
		msgHasConfig = "{0}\u5B58\u5728\u5458\u5DE5\u85AA\u8D44\u914D\u7F6E\u6570\u636E\uFF0C\u4E0D\u5141\u8BB8\u5220\u9664\uFF01";
		msgHasPaid = "{0}\u5B58\u5728\u5458\u5DE5\u85AA\u8D44\u53D1\u653E\u6570\u636E\uFF0C\u4E0D\u5141\u8BB8\u5220\u9664\uFF01";
		msgHasCompPlan = "{0}\u5B58\u5728\u5458\u5DE5\u8C03\u85AA\u8BB0\u5F55\uFF0C\u4E0D\u5141\u8BB8\u5220\u9664\uFF01";
		msgHasBenePlan = "{0}\u5B58\u5728\u793E\u4FDD\u7F34\u8D39\u5386\u53F2\uFF0C\u4E0D\u5141\u8BB8\u5220\u9664\uFF01";
		msgSucc = "{0}\u5DF2\u5220\u9664\uFF01";
	}

	public String execute() throws Exception {
		IEmpSalaryAcctversionBo esavBo = (IEmpSalaryAcctversionBo) getBean("empsalaryacctversionBo");
		Empsalaryacctversion esav = esavBo.loadObject(id,
				new String[] { "esavEsac" });
		if (esav == null) {
			addActionErrorInfo(msgNoData, new Object[0]);
			return "input";
		}
		if (esav.getEsavValidTo() != null) {
			addActionErrorInfo(msgHistVer, new Object[] { esav.getEsavEsac()
					.getEsacName() });
			return "input";
		}
		ISalaryconfBo salaryConfBo = (ISalaryconfBo) getBean("salaryconfBo");
		int num = salaryConfBo.hasSalaryConfigByAcctVersion(id);
		if (num > 0) {
			addActionErrorInfo(msgHasConfig, new Object[] { esav.getEsavEsac()
					.getEsacName() });
			return "input";
		}
		ISalaryPaidBo salaryPaidBo = (ISalaryPaidBo) getBean("salaryPaidBo");
		if (salaryPaidBo.hasSalaryPayByAcctVersion(id) > 0) {
			addActionErrorInfo(msgHasPaid, new Object[] { esav.getEsavEsac()
					.getEsacName() });
			return "input";
		}
		ICompaplanBo compaplanBo = (ICompaplanBo) getBean("compaplanBo");
		if (compaplanBo.hasSalaryAdjByAcctVersion(id) > 0) {
			addActionErrorInfo(msgHasCompPlan, new Object[] { esav
					.getEsavEsac().getEsacName() });
			return "input";
		}
		IEmpBenefitPlanBo benefitPlanBo = (IEmpBenefitPlanBo) getBean("empbenefitplanBo");
		int planNum = benefitPlanBo.hasBenefitPlanByAcctVersion(id);
		if (planNum > 0) {
			addActionErrorInfo(msgHasBenePlan, new Object[] { esav
					.getEsavEsac().getEsacName() });
			return "input";
		} else {
			addSuccessInfo(msgSucc, new Object[] { esav.getEsavEsac()
					.getEsacName() });
			esavBo.deleteAcctVersion(id, esav.getEsavEsac().getId());
			return "success";
		}
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	private static final long serialVersionUID = 1L;
	private String id;
	private String msgNoData;
	private String msgHistVer;
	private String msgHasConfig;
	private String msgHasPaid;
	private String msgHasCompPlan;
	private String msgHasBenePlan;
	private String msgSucc;
}
